using System;
using System.Collections;
using System.Drawing;
using System.Drawing.Drawing2D;
using PickGold.Charting;

namespace PickGold.Charting.ChartTypes
{
	internal class StepLineChart : LineChart
	{
		protected override GraphicsPath Draw3DSurface(ChartArea area, ChartGraphics graph, Matrix3D matrix, LightStyle lightStyle, DataPoint3D prevDataPointEx, float positionZ, float depth, ArrayList points, int pointIndex, int pointLoopIndex, float tension, DrawingOperationTypes operationType, float topDarkening, float bottomDarkening, PointF thirdPointPosition, PointF fourthPointPosition, bool clippedSegment)
		{
			GraphicsPath path2;
			GraphicsPath path3;
			GraphicsPath path = ((operationType & DrawingOperationTypes.CalcElementPath) == DrawingOperationTypes.CalcElementPath) ? new GraphicsPath() : null;
			if (base.centerPointIndex == 0x7fffffff)
			{
				base.centerPointIndex = base.GetCenterPointIndex(points);
			}
			DataPoint3D secondPoint = (DataPoint3D)points[pointIndex];
			int neighborPointIndex = pointIndex;
			DataPoint3D firstPoint = ChartGraphics.FindPointByIndex(points, secondPoint.index - 1, base.multiSeries ? secondPoint : null, ref neighborPointIndex);
			DataPoint3D pointd3 = secondPoint;
			if (prevDataPointEx.dataPoint.IsEmpty)
			{
				pointd3 = prevDataPointEx;
			}
			else if (firstPoint.index > secondPoint.index)
			{
				pointd3 = firstPoint;
			}
			Color backColor = base.useBorderColor ? pointd3.dataPoint.BorderColor : pointd3.dataPoint.Color;
			ChartDashStyle borderDashStyle = pointd3.dataPoint.BorderDashStyle;
			if (pointd3.dataPoint.IsEmpty && (pointd3.dataPoint.Color == Color.Empty))
			{
				backColor = Color.Gray;
			}
			if (pointd3.dataPoint.IsEmpty && (pointd3.dataPoint.BorderDashStyle == ChartDashStyle.NotSet))
			{
				borderDashStyle = ChartDashStyle.Solid;
			}
			DataPoint3D pointd4 = new DataPoint3D();
			pointd4.xPosition = secondPoint.xPosition;
			pointd4.yPosition = firstPoint.yPosition;
			bool flag = true;
			if ((pointIndex + 1) < points.Count)
			{
				DataPoint3D pointd5 = (DataPoint3D)points[pointIndex + 1];
				if (pointd5.index == firstPoint.index)
				{
					flag = false;
				}
			}
			if ((base.centerPointIndex != 0x7fffffff) && (pointIndex >= base.centerPointIndex))
			{
				flag = false;
			}
			if (flag)
			{
				pointd4.dataPoint = secondPoint.dataPoint;
				path2 = graph.Draw3DSurface(area, matrix, lightStyle, SurfaceNames.Top, positionZ, depth, backColor, pointd3.dataPoint.BorderColor, pointd3.dataPoint.BorderWidth, borderDashStyle, firstPoint, pointd4, points, pointIndex, 0f, operationType, LineSegmentType.First, base.showPointLines, false, area.ReverseSeriesOrder, base.multiSeries, 0, true);
				graph.frontLinePen = null;
				pointd4.dataPoint = firstPoint.dataPoint;
				path3 = graph.Draw3DSurface(area, matrix, lightStyle, SurfaceNames.Top, positionZ, depth, backColor, pointd3.dataPoint.BorderColor, pointd3.dataPoint.BorderWidth, borderDashStyle, pointd4, secondPoint, points, pointIndex, 0f, operationType, LineSegmentType.Last, base.showPointLines, false, area.ReverseSeriesOrder, base.multiSeries, 0, true);
				graph.frontLinePen = null;
			}
			else
			{
				pointd4.dataPoint = firstPoint.dataPoint;
				path3 = graph.Draw3DSurface(area, matrix, lightStyle, SurfaceNames.Top, positionZ, depth, backColor, pointd3.dataPoint.BorderColor, pointd3.dataPoint.BorderWidth, borderDashStyle, pointd4, secondPoint, points, pointIndex, 0f, operationType, LineSegmentType.Last, base.showPointLines, false, area.ReverseSeriesOrder, base.multiSeries, 0, true);
				graph.frontLinePen = null;
				pointd4.dataPoint = secondPoint.dataPoint;
				path2 = graph.Draw3DSurface(area, matrix, lightStyle, SurfaceNames.Top, positionZ, depth, backColor, pointd3.dataPoint.BorderColor, pointd3.dataPoint.BorderWidth, borderDashStyle, firstPoint, pointd4, points, pointIndex, 0f, operationType, LineSegmentType.First, base.showPointLines, false, area.ReverseSeriesOrder, base.multiSeries, 0, true);
				graph.frontLinePen = null;
			}
			if (path != null)
			{
				if ((area.Common.ProcessModeRegions && (path2 != null)) && (path2.PointCount > 0))
				{
					area.Common.HotRegionsList.AddHotRegion(path2, false, graph, prevDataPointEx.dataPoint, prevDataPointEx.dataPoint.series.Name, prevDataPointEx.index - 1);
				}
				if ((path3 != null) && (path3.PointCount > 0))
				{
					path.AddPath(path3, true);
				}
			}
			return path;
		}

		protected override void DrawLine(ChartGraphics graph, CommonElements common, DataPoint point, Series series, PointF[] points, int pointIndex, float tension)
		{
			if (pointIndex > 0)
			{
				PointF tf = points[pointIndex - 1];
				PointF tf2 = new PointF(points[pointIndex].X, points[pointIndex - 1].Y);
				PointF tf3 = points[pointIndex];
				graph.DrawLineRel(point.Color, point.BorderWidth, point.BorderDashStyle, graph.GetRelativePoint(tf), graph.GetRelativePoint(tf2), series.ShadowColor, series.ShadowOffset);
				graph.DrawLineRel(point.Color, point.BorderWidth, point.BorderDashStyle, graph.GetRelativePoint(tf2), graph.GetRelativePoint(tf3), series.ShadowColor, series.ShadowOffset);
				if (common.ProcessModeRegions)
				{
					GraphicsPath path = new GraphicsPath();
					try
					{
						path.AddLine(tf2, tf3);
						path.Widen(new Pen(point.Color, (float)(point.BorderWidth + 2)));
					}
					catch (OutOfMemoryException)
					{
					}
					catch (ArgumentException)
					{
					}
					PointF empty = PointF.Empty;
					float[] coord = new float[path.PointCount * 2];
					PointF[] pathPoints = path.PathPoints;
					for (int i = 0; i < path.PointCount; i++)
					{
						empty = graph.GetRelativePoint(pathPoints[i]);
						coord[2 * i] = empty.X;
						coord[(2 * i) + 1] = empty.Y;
					}
					common.HotRegionsList.AddHotRegion(path, false, coord, point, series.Name, pointIndex);
					path.Dispose();
					path = new GraphicsPath();
					try
					{
						path.AddLine(tf, tf2);
						path.Widen(new Pen(point.Color, (float)(point.BorderWidth + 2)));
					}
					catch (OutOfMemoryException)
					{
					}
					catch (ArgumentException)
					{
					}
					coord = new float[path.PointCount * 2];
					pathPoints = path.PathPoints;
					for (int j = 0; j < path.PointCount; j++)
					{
						empty = graph.GetRelativePoint(pathPoints[j]);
						coord[2 * j] = empty.X;
						coord[(2 * j) + 1] = empty.Y;
					}
					common.HotRegionsList.AddHotRegion(path, false, coord, series.Points[pointIndex - 1], series.Name, pointIndex - 1);
					path.Dispose();
				}
			}
		}

		public override Image GetImage(ChartTypeRegistry registry)
		{
			return (Image)registry.ResourceManager.GetObject(this.Name + "ChartType");
		}

		public override string Name
		{
			get
			{
				return "StepLine";
			}
		}
	}
}

